<?php

namespace App\Http\Controllers;

use App\Http\Requests\RecordRemarkRequest;
use App\Models\RecordRemark;
use App\Transformers\RecordRemarkTransformer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RecordRemarkController extends Controller
{
    /**
     * @api {post} /api/record/remark 会员手机标记添加
     * @apiGroup RecordRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {String} status  枚举 成功回访、停机、关机、空号、无人接听、直接挂掉、用户正忙、不在服务区
     * @apiParam {int} record_id  录音列表id
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 201 OK
     */
    public function store(RecordRemarkRequest $request, RecordRemark $recordRemark){
        $data = $request->all();
        $data['user_id'] = Auth::id();
        $recordRemark->create($data);
        return $this->response->created();
    }
    /**
     * @api {patch} /api/record/remark/:id 通话录音标记修改
     * @apiGroup RecordRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} id 备注列表Id(url中传入，必传参数)
     * @apiParam {String} status  枚举  成功回访、停机、关机、空号、无人接听、直接挂掉、用户正忙、不在服务区
     *
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *       {
     *        "message": "修改成功"
     *       }
     */
    public function update(RecordRemarkRequest $request, RecordRemark $recordRemark){
        $data = $request->all();
        $recordRemark->update($data);
        return response()->json(['message' => '修改成功']);
    }
    /**
     * @api {delete} /api/record/remark/:id 通话录音标记删除
     * @apiGroup  RecordRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} id 备注列表Id(url中传入，必传参数)
     *
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 204 OK
     */
    public function destroy(RecordRemark $recordRemark){
        $recordRemark->delete();
        return $this->response->noContent();
    }

    /**
     * @api {get} /api/record/remark/:id 通话录音标记展示
     * @apiGroup  RecordRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} id 备注列表Id(url中传入，必传参数)
     *
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *       {
     *           "id": 3,
     *           "status": "成功回访",
     *           "record_id": 1,
     *           "user_id": 1,
     *           "created_at": "2019-01-03 12:02:39",
     *           "updated_at": "2019-01-03 12:02:39"
     *       }
     */
    public function show(RecordRemark $recordRemark){
        return $this->response->item($recordRemark, new RecordRemarkTransformer());
    }
    /**
     * @api {get} /api/record/remark?include=user 通话录音标记列表
     * @apiGroup  RecordRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} id 录音Id
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *       {
     *           "data": [
     *               {
     *                   "id": 2,
     *                   "status": "成功回访",
     *                   "record_id": 31,
     *                   "user_id": 1,
     *                   "created_at": "2019-01-03 11:57:04",
     *                   "updated_at": "2019-01-03 11:57:04"
     *               }
     *            ]
     *        }
     */
    public function index(RecordRemark $recordRemark,Request $request){
        $validatedData = $request->validate([
            'id' => 'required|exists:phone_records,id'
        ]);
        $data = $recordRemark->where('record_id',$validatedData['id'])->get();
        return $this->response->collection($data, new RecordRemarkTransformer());
    }
}
